<template>
    <div class="page" v-if="movie.images">
        <head-item :title="movie.title"></head-item>
        <div class="container">
            <div class="top">
                <img :src="movie.images.small" class="background">
                <div class="toptitle">
                    <div class="bigtitle">{{movie.title}}</div>
                    <div class="city">{{movie.countries[0]}} · {{movie.year}}</div>
                    <div class="like">
                        <span class="collect">{{movie.collect_count}}</span>人喜欢
                        <span class="likes">{{movie.comments_count}}</span>条评论
                    </div>
                </div>
            </div>
            <img :src="movie.images.small" class="picture">
            <div class="introduction">
                <p class="title">{{movie.original_title}}</p>
                <div class="rating">
                    <p>
                        <span class="info">评分</span> 
                        <img  :src="item==1?require('../../assets/images/icon/star.png'):require('../../assets/images/icon/none-star.png')" 
                        class="star" v-for="(item,index) of stars" :key="index">
                        <span class="average">{{movie.rating.average}}</span>
                    </p>
                    <p><span class="info">导演</span> {{directors.join('/')}}</p>
                    <p><span class="info">影人</span>{{casts.join(' / ')}}</p>
                    <p><span class="info">类型</span>{{type.join('、')}}</p>
                </div>
            </div>

            <div class="introduction">
                <p class="plot">剧情简介</p>
                <p>{{movie.summary | formatPlot}}</p>
            </div>

            <div class="casts introduction">
                <p class="plot">影人</p>
                <div class="grid">
                    <div v-for="item of movie.casts" :key="item.id">
                        <img :src="item.avatars.small" class="c-img">
                        <p>{{item.name}}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import HeadItem from '@/components/Head.vue';
import Http from '@/api/douban.js'
    export default {
        async mounted() {
            var {id} = this.$route.query;
            let casts = [];
            let directors = [];
            let res = await Http.getDetail(id);
            this.movie = res;
            this.type = res.genres;
            this.movie.casts.forEach(item=>{
                casts.push(item.name);
            });
            this.movie.directors.forEach(item=>{
                directors.push(item.name)
            });
            this.directors = directors;
            this.casts = casts;
        },
        components:{
            HeadItem
        },
        data(){
            return {
                movie:{},
                type:[],
                casts:[],
                directors:[],
            }
        },
        computed:{
            stars(){
                var value = this.movie.rating.stars.substring(0,1);
                var arr = [];
                for (var i = 1; i <= 5; i++) {
                    if (i <= value) {
                        arr.push(1)
                    } else {
                        arr.push(0)
                    }
                    }
                 return arr;
            }
        },
        filters:{
            formatPlot(str){
                if(str){
                    if(str.length>105){
                        return str.slice(0,105)+"..."
                    }else{
                        return str
                    }
                }
            }
        }
    }
</script>

<style lang="less" scoped>
@top:46px;
@bottom:50px;
    .page{
        padding-top: @top;
    }
    .container{
        width: 100%;
        position: relative;
        .top{
            width:100%;
            height: 160px;
            position: relative;
            overflow: hidden;
            box-shadow:0 0 30px 10px;
        }
    }
    .background{
        width: 100%;
        height: 160px;
        filter: blur(15px);
    }
    div.toptitle{
        position: absolute;
        top: 24.5px;
        left: 20px;
        color: #fff;
        font-size: 15px;
    }
    .bigtitle{
    font-weight: bold;
    font-size: 17.5px;
    }
    .city{
        padding-top: 15px;
    }
    .collect,.likes{
        color:#e6234b;
        padding-right: 10px;
    }
    .like{
        padding-top: 25px;
    }
    .likes{
        padding-left: 10px;
    }
    .picture{
    position: absolute;
    top: 98px;
    right: 15px;
    z-index: 10;
    width: 70px;
    height: 97.5px;
    }
    .introduction{
        border-bottom: 1px #dcdcdc solid;
        font-size: 15px;
        padding: 20px;
        padding-top: 25px;
        width: 375px;
        .title{
            color: #333;
            font-weight: bold;
            font-size: 17.5px;
            padding-bottom: 20px;
        }
    }
    .info{
        color:#9a9a9a;
        padding-right: 17.5px;
        font-size: 15px;
    }
    .plot{
    color: #9a9a9a;
    padding-bottom: 15px;
    }
    .star{
        height: 15px;
        width: 15px;
    }
    .average{
        padding-left: 5px;
        color: #405f80;
    }
    .rating{
        font-size: 15px;
    }
    .grid{
        display: grid;
        width: 100%;
        grid-template-columns: repeat(4,100px);
        gap: 15px;
        overflow-x: scroll;
        overflow-y: hidden;
    }
    .grid::-webkit-scrollbar{
        display: none;
    }
    .c-img{
        width: 100px;
    }
</style>